<?php

namespace App\Http\Controllers\Admins\Customer;

use App\Http\Controllers\Admins\BaseAdminController;
use App\Models\Appointment;
use App\Models\OperationalLogs;
use App\Models\Setting;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class CustomerController extends BaseAdminController
{

    /**
     * 预约须知
     *
     * @param Request $request
     * @return Application|Factory|View|RedirectResponse
     */
    public function telephone(Request $request){
        $key = 'customer_telephone';
        if($request->isMethod('post')){
            $telephone = $request->get('telephone','');
            if(!$telephone){
                return $this->retError('电话不能为空',$request);
            }
            $vp = VerifyMobile($telephone,true);
            if($vp['code'] == 0){
                return $this->retError($vp['msg_zh'],$request);
            }
            $logs = [
                'admin_id'=>$request->get('admin_id'),
                'operate_menu'=>OperationalLogs::$operateItem['customer_manage'],
                'operate_item'=>OperationalLogs::$operate['customer_telephone_setting'],
                'operate_content'=>OperationalLogs::$operate['customer_telephone_setting'],
            ];
            DB::beginTransaction();
            $where = [
                'key'=>$key
            ];
            try {
                Setting::query()->where($where)->update([
                    'value'=>$telephone,
                ]);
                #添加操作日志
                OperationalLogs::AddOperationalLogs($logs);
                DB::commit();
                return $this->retSuccess();
//                return AdminRet('操作成功!');
            } catch (\Exception $exception) {
                DB::rollBack();
                return $this->retError($exception->getMessage());
            }
        }
        $subtitle = '客服电话';
        $telephone = Setting::getDataByKey($key);
        $params = [
            'url'=>'',
            'success'=>'success'
        ];
        $compact = compact('subtitle','telephone','params');
        return view('v1.admin.customer.telephone',$compact);
    }

}
